package com.simteek.testredis.service;

import com.simteek.testredis.dao.BookDao;
import com.simteek.testredis.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class BookService {
    @Autowired
    private BookDao bookDao;

    public void save(String name, String author, String publicDate) {
        Book book = new Book();
        book.set_id(UUID.randomUUID().toString());
        book.setName(name);
        book.setAuthor(author);
        book.setPublicDate(publicDate);
        bookDao.save(book);
    }

    public List findAll() {
        return bookDao.findAll();
    }

//    public List findBy(String by, String value) {
//        if ("firstName".equals(by)) {
//            return userRepository.findByFirstNameLike(value);
//        } else if ("lastName".equals(by)) {
//            return userRepository.findByLastNameLike(value);
//        } else if ("age".equals(by)) {
//            return userRepository.findByAge(Integer.parseInt(value));
//        }
//        return null;
//    }

    public void deleteById(String _id) {
        bookDao.delete(_id);
    }
}
